<template>
  <div>
    文档资源
    <el-upload
      class="upload-demo"
      drag
      action="https://jsonplaceholder.typicode.com/posts/"
      multiple
      accept=".doc, .docx, .pdf, .xls, .xlsx, .txt"
      :before-upload="beforeUpload"
    >
      <i class="el-icon-upload" />
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div slot="tip" class="el-upload__tip">只能上传doc/docx文件</div>
    </el-upload>
  </div>
</template>

<script>
export default {
  name: 'Document',
  data() {
    return {};
  },
  methods: {
    beforeUpload(file) {
      const fileType = file.name.replace(/.+\./, '');
      const fileVer = ['doc', 'docx', 'pdf', 'xls', 'xlsx', 'txt'].includes(fileType);
      if (!fileVer) {
        this.$message.error('格式不正确');
        return false;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
